package designpatterns.strategy;

import java.util.ArrayList;
import java.util.Arrays;

public class SelectionSort extends GeneralSort {
	@Override
	public ArrayList<Integer> sort(ArrayList<Integer> data) {
		internalData = data.toArray(new Integer[data.size()]);
		
		ExecTime = System.currentTimeMillis();
		
		for (int i = 0; i < internalData.length; i++) {
			int minPos = i;
			int cursor = i;
			int tmp = 0;
			
			while (cursor < internalData.length) {
				if (internalData[cursor] < internalData[minPos]) {
					minPos = cursor;
				}
				cursor++;
			}
			
			tmp = internalData[i];
			internalData[i] = internalData[minPos];
			internalData[minPos] = tmp;
			
		}
				
		ExecTime = System.currentTimeMillis() - ExecTime;
		
		return new ArrayList <Integer> (Arrays.asList(internalData));
	}

	@Override
    public String getName() {
	    // TODO Auto-generated method stub
	    return "SelectionSort " + isSorted();
    }

}
